import jpcap.*;

import java.util.ArrayList;

/**
 * Project: SecuritySnort
 * This class will take care of printing the info for the selected device.
 *
 * @author Jonathan Buttner
 * @version March 5, 2010
 */

public class ConInfoCmd extends Command
{
	
	/**************************************************************************
	 * 							Globals
	 *************************************************************************/
	private NetworkInterface _conInfo;
	/**************************************************************************
	 * 							Constructors
	 *************************************************************************/
	
	/**
	 * This constructor sets up the object.
	 * 
	 * @param dev is a string representing the connection
	 * device info.
	 */
	public ConInfoCmd( NetworkInterface dev )
	{
		_name = "coninfo";
		_conInfo = dev;
	}
	
	/**************************************************************************
	 * 							Public Methods
	 *************************************************************************/
	/**
	 * This method executes the connection info command.
	 * 
	 * @param cmdLine is an ArrayList holding the arguments
	 * passed in through the console.
	 * NOTE: cmdLine not used...
	 */
	public void exeCommand( ArrayList < String > cmdLine )
	{
		if ( _conInfo == null )
			System.out.println( "You have not selected a device yet."
					+"\nUse the 'pickdevice' command to choose a device." );
		else
		{
			System.out.println( _conInfo.name + "("
					+ _conInfo.description + ")" );
			System.out.println( "    data link:" + _conInfo.datalink_name + "("
					+ _conInfo.datalink_description+")" );
			System.out.print( "    MAC address:");
			
			for ( byte b : _conInfo.mac_address )
				System.out.print( Integer.toHexString(b&0xff) + ":" );
			
			System.out.println();
			
			for ( NetworkInterfaceAddress a : _conInfo.addresses )
				System.out.println( "    address:" + a.address + " "
						+ a.subnet + " " + a.broadcast );
		}
	}
	
	/**
	 * This method is used to set the connection device being used.
	 * 
	 * @param dev is the connection device.
	 */
	public void setDev( NetworkInterface dev )
	{
		_conInfo = dev;
	}
}
